package com.bite.spring.demo.sample;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2025-11-02
 * Time: 16:35
 */
@RequestMapping("resp")
@RestController
//@Controller
public class RespController {
    /**
     * 返回页面
     * @return
     */
    @RequestMapping("r1")
    public String returnPage(){
        //前端对应的路径是从static往下数
        return "/aa/index.html";
    }


    /**
     * 返回数据
     * @return
     */
    @RequestMapping("r2")
    @ResponseBody
    public String returnData(){
        //前端对应的路径是从static往下数
        return "我是前端要的数据";
    }

    @RequestMapping("/r3")
//    @ResponseBody
    public String returnHTML(){
        return "<h1>我是一级标签</h1>";
    }

    @RequestMapping(value = "/r4", produces = "text/plain")
    public String returnText(){
        return "<h1>我是一级标签</h1>";
    }

    @RequestMapping(value = "/r5")
    public UserInfo returnJson(){
        UserInfo userInfo = new UserInfo("zhangsan", 1, 1);
        return userInfo;
    }

    @RequestMapping(value = "/r6")
    public UserInfo setStatus(HttpServletResponse response){
        response.setStatus(404);
        UserInfo userInfo = new UserInfo("zhangsan", 1, 1);
        return userInfo;
    }

    @RequestMapping(value = "/r7")
    public String setHeader(HttpServletResponse response){
        response.setHeader("myHeader", "myHeader");

        return "设置成功";
    }
}
